package com.wing.purchase.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.purchase.dao.PurchasePlanDetailDao;
import com.wing.purchase.model.entity.PurchasePlanDetail;
import com.wing.purchase.model.request.PurchasePlanDetailForm;
import com.wing.purchase.model.response.PurchasePlanCheckVO;
import com.wing.purchase.model.response.PurchasePlanDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 领料计划明细-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class PurchasePlanDetailServiceImpl extends ServiceImpl<PurchasePlanDetailDao, PurchasePlanDetail> implements PurchasePlanDetailService {

    @Override
    public int add(PurchasePlanDetailForm purchasePlanDetailForm) {

        //校验

        PurchasePlanDetail purchasePlanDetail =new PurchasePlanDetail();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(PurchasePlanDetail.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(purchasePlanDetailForm, purchasePlanDetail, copyOptions);

        return baseMapper.insert(purchasePlanDetail);
    }

    @Override
    public List<PurchasePlanDetailVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<PurchasePlanDetailVO> pageList4app(Page page, Map<String, Object> params) {
        List<PurchasePlanDetailVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public PurchasePlanDetailVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public int changePlanCheckStatus(Integer newStatus, Integer oldStatus, String planNo, Long purchaseUrgencyId) {
        return baseMapper.changePlanCheckStatus(newStatus, oldStatus, planNo, purchaseUrgencyId);
    }

    @Override
    public List<PurchasePlanCheckVO> findCheckInfoList(Map<String, Object> params) {
        return baseMapper.findCheckInfoList(params);
    }
}
